#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <sys/sem.h>
#include <semaphore.h>
// through the sem sync

int semid;
union semun {
  int val;
  struct sedmid_ds *buf;
  unsigned short *array;
} mysemun;

struct sembuf mybuf;


int main()
{
  if (-1 == (semid = semget(ftok("a.c", 0777), 3, IPC_CREAT | 0777)))
  {
    perror("semget");
    exit(1);
  }
  mysemun.val = 0;
  if (-1 == semctl(semid, 0, SETVAL, mysemun))
  {
    perror("semctl");
    exit(1);
  }
  // mybuf.sem_num = 0;
  // mybuf.sem_flg = 0;
  for (int i=0; i<10; ++i)
  {
    printf("parent i = %d\n", i);
    usleep(100);
  }
  mybuf.sem_op = 1;
  semop(semid, &mybuf, 1);
  while(1);


  return 0;
}
